package com.jams.goodox.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jams.goodox.R;
import com.jams.goodox.TownApplicationLike;
import com.jams.goodox.entity.OnlineShoppingCommentBean;
import com.jams.goodox.utils.DensityUtil;
import com.jams.goodox.utils.StringUtils;
import com.jams.goodox.utils.ViewUtils;
import com.jams.goodox.widget.NoScrollGridView;
import com.jams.goodox.widget.StarsLayout;
import com.jams.library.commonAdapter.ListCommonAdapter;
import com.jams.library.commonAdapter.ListCommonViewHolder;
import com.jams.library.commonAdapter.RecycleCommonAdapter;
import com.jams.library.commonAdapter.RecycleCommonViewHolder;

import java.util.List;

/**
 * Created by liwei on 2016/7/27 10:10
 * Email: liwei@uama.com.cn
 * Description:
 */
public class OnlineShoppingCommentAdapter extends RecycleCommonAdapter<OnlineShoppingCommentBean> {
    public OnlineShoppingCommentAdapter(Context context, List<OnlineShoppingCommentBean> data) {
        super(context, data, R.layout.ols_about_comment_item);
    }

    @Override
    public void convert(RecycleCommonViewHolder helper, OnlineShoppingCommentBean bean, int position) {
        helper.setText(R.id.tv_nickname, String.format("%s:", bean.getAppraiseUser()))
                .setText(R.id.tv_time, bean.getAppraiseTime())
                .setText(R.id.tv_comment, bean.getAppraiseContent());

        TextView commentView = helper.getView(R.id.tv_comment);
        // 如果评论为空就不显示评论区
        if (!TextUtils.isEmpty(bean.getAppraiseContent())) {
            commentView.setVisibility(View.VISIBLE);
        } else {
            commentView.setVisibility(View.GONE);
        }

        ViewGroup replyLayout = helper.getView(R.id.reply_layout);
        // 如果没有回复就不显示回复区
        if ("1".equals(bean.getIsReply())) {
            replyLayout.setVisibility(View.VISIBLE);
            helper.setText(R.id.tv_reply, String.format("回复: %s", bean.getReplyContent()));
        } else {
            replyLayout.setVisibility(View.GONE);
        }

        StarsLayout starsLayout = helper.getView(R.id.stars_layout);
        float qualityRating = StringUtils.toFloat(bean.getAppraiseQuality());
//        float speedRatting = StringUtils.toFloat(bean.getAppraiseSpeed());
//        float averageRating = (qualityRating + speedRatting) / 2;
        starsLayout.setBlingStar((int) qualityRating);

        if(bean.getUrlList()==null||bean.getUrlList().size()==0)return;
        NoScrollGridView blankClickGridView = helper.getView(R.id.gv_innings_item);
        blankClickGridView.setFocusable(false);
        blankClickGridView.setAdapter(new ListCommonAdapter<String>(mContext,bean.getUrlList(),R.layout.pic_img_list) {
            @Override
            public void convert(ListCommonViewHolder helper, String item, int position) {
                int newWidth = (TownApplicationLike.width - DensityUtil.dp2px(mContext, 75)) / 4;
                SimpleDraweeView simpleDraweeView=helper.getView(R.id.sdv_only_image_item);
                View rl_only_image=helper.getView(R.id.rl_only_image);
                ViewUtils.setAbsListViewLayoutWH(rl_only_image,newWidth, newWidth);
                simpleDraweeView.setImageResource(R.mipmap.product_ep);
            }
        });

    }
}
